package top.kaoshanji.p1ch03a;

import java.util.Date;

/**
 * 代码清单-p1ch03a-67页a：表示文件夹的类
 * author kaoshanji
 * ^_^
 * create time 2025/2/17 14:01
 */
public class MyFolder {

    // 文件夹名称
    private String name;

    // 创建时间
    private Date createTime;

    // 上级文件夹
    private MyFolder parent;

    // 包含的文件
    private MyFile[] files;

    // 包含的子文件夹
    private MyFolder[] subFolders;

    // 统计文件夹下文件的大小
    public int totalSize() {
        int totalSize = 0;
        if (null != files) {
            for (MyFile file: files) {
                totalSize += file.getSize();
            }
        }

        if (null != subFolders) {
            for (MyFolder folder: subFolders) {
                totalSize += folder.totalSize();
            }
        }

        return totalSize;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public MyFolder getParent() {
        return parent;
    }

    public void setParent(MyFolder parent) {
        this.parent = parent;
    }

    public MyFile[] getFiles() {
        return files;
    }

    public void setFiles(MyFile[] files) {
        this.files = files;
    }

    public MyFolder[] getSubFolders() {
        return subFolders;
    }

    public void setSubFolders(MyFolder[] subFolders) {
        this.subFolders = subFolders;
    }
}
